<?php

namespace App\Service\Activity\v1_3_0;

use App\Model\UserProfile;
use App\Service\BaseService;
use App\Helpers\AliyunUtil;
/**
 * 邀请有奖页面信息
 */
class InviteInfoService extends BaseService
{
    public function handle()
    {
        $userId = $this->getUserId();
        $userProfile = UserProfile::getProfile($userId);
        $inviteCode = intval($userProfile->user_profile_id);

        //邀请下载链接
        $url = 'http://www.hudongailian.com/xinmi/register.html?invitecode='.$inviteCode;
        $qrCodeFileName = 'qrcode/images_'.rand(1,9999);
        $urlbase  = AliyunUtil::IMG_HOST.'invite_bgqrcode01.png';
        $base64 = base64_encode($inviteCode) ;
        $text = "/watermark,text_{$base64},color_FFFFFF,shadow_80,t_100,g_se,x_200,y_246";

        if($inviteCode>0){
            $inviteLink = AliyunUtil::posterQrCode($url,$qrCodeFileName,$urlbase,180,30,10).$text;
        }else{
            $inviteLink = AliyunUtil::posterQrCode($url,$qrCodeFileName,$urlbase,180,30,10);//图片链接
        }

        return [
            //邀请码
            'invite_code' => $inviteCode,
            //邀请链接
            'invite_link' => $inviteLink,
        ];
    }
}
